import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class MainFrame extends JApplet {
	
	// Main Banner properties
	private JLabel lblBanner= new JLabel(new ImageIcon("image/Restaurant-banner2.jpg"));
	private CardLayout mainCardLayout = new CardLayout();
	private JTextArea jtaRestaurantFinderText = new JTextArea(1,10);
	private JPanel centerPane = new JPanel(mainCardLayout);
	private JLabel lblLogo = new JLabel(new ImageIcon("image/logo.jpg"));
	
	
	// Customer interface container
	protected static CardLayout customerCardLayout = new CardLayout();
	protected static JPanel customerContainer = new JPanel(customerCardLayout);
	private CustomerSearch customerSearch = new CustomerSearch();
	private SearchHits searchHits = new SearchHits();
	
	
	// Restaurant interface container
	protected static CardLayout restaurantCardLayout = new CardLayout(); // CardLayout to flip between owner-interface componest
	protected static JPanel restaurantContainer = new JPanel(restaurantCardLayout); // container to hold the restaurant interface sub-pannels
	private OwnerLogin ownerLogin = new OwnerLogin(); // Instance of owner log-in class
	private OwnerChoice ownerChoice = new OwnerChoice(); // Instance of the owner-choice class
	protected static OwnerEdit ownerEdit = new OwnerEdit(); // Instance of the ownerEdit class
	private JButton jbtOwnerLogin = new JButton("Owner Login");
		
	
	/**
	 * Create the applet
	 */
	public MainFrame() {
		centerPane.setLayout(new BorderLayout());
		getContentPane().setLayout(new BorderLayout(0, 0));
		
		// Create a panel in the north to hold the logo 
		JPanel northPanel = new JPanel();
		northPanel.setLayout(new BorderLayout());
		getContentPane().add(northPanel, BorderLayout.NORTH);
		
		// Edit Restaurant finder Logo text
		jtaRestaurantFinderText.setText("\nRESTAURANT FINDER");
		jtaRestaurantFinderText.setLineWrap(true);
		jtaRestaurantFinderText.setWrapStyleWord(true);
		jtaRestaurantFinderText.setBackground(UIManager.getColor("inactiveCaption"));
		jtaRestaurantFinderText.setFont(new Font("Bradley Hand ITC", Font.BOLD, 20));
		jtaRestaurantFinderText.setEditable(false);
		
		
		// Organising the logo and text into one panel
		JPanel upperNorthPanel  = new JPanel(new BorderLayout());
		JPanel lowerNorthPanel = new JPanel(new BorderLayout());
		JPanel logoTextPanel = new JPanel(new BorderLayout());
		
		
		//Organising the logo and button in one panel
		logoTextPanel.add(jtaRestaurantFinderText, BorderLayout.EAST);
		logoTextPanel.add(lblLogo, BorderLayout.CENTER);
		upperNorthPanel.add(logoTextPanel, BorderLayout.WEST);
		upperNorthPanel.add(lblBanner, BorderLayout.CENTER);
		lowerNorthPanel.add(jbtOwnerLogin, BorderLayout.EAST);
		
		//putting the logo and banner into the north panel
		northPanel.add(upperNorthPanel, BorderLayout.CENTER);
		northPanel.add(lowerNorthPanel, BorderLayout.SOUTH);
		
		
		
		// Set the panel in the east
		JPanel westPanel = new JPanel();
		getContentPane().add(westPanel, BorderLayout.WEST);
		
		// Add tabbedPanes to hold the customer and restaurant interfaces
		centerPane.add(customerContainer);
		//centerPane.add(restaurantContainer); 
			
		
		
		// Add owner interface components
		restaurantContainer.add(ownerLogin, "ownerLogin");
		restaurantContainer.add(ownerChoice, "ownerChoice");
		restaurantContainer.add(ownerEdit, "ownerEdit");
		
		// Add the customer interface components
		customerContainer.add(customerSearch, "customerSearch");
		customerContainer.add(searchHits, "searchHits");
		
		
		// Add tabbedPane to main frame
		getContentPane().add(centerPane, BorderLayout.CENTER);
		
		
		// Switch to owner Layout when ownerLogin button is clicked
		jbtOwnerLogin.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				setToOwnerInterface();
			}
		});
		
	}
	
	//Set interface to the owner interface
	private void setToOwnerInterface(){
		centerPane.remove(customerContainer);
		centerPane.add(restaurantContainer);
		this.revalidate();
	}
	
	public static void main(String[] args){
		MainFrame mainframe = new MainFrame();
		JFrame frame = new JFrame();
		frame.getContentPane().add(mainframe);
		frame.setSize(new Dimension(1100,650));
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setIconImage((new ImageIcon("image/restaurant-finder.png")).getImage());
		frame.setVisible(true);
	}
}
